<?php
define ( 'BEGIN_TIME', ( int ) YII_BEGIN_TIME );
class WebApplication extends CWebApplication {

	/**
	 * 预初始化
	 *
	 * @see CModule::preinit()
	 */
	public function preinit() {
		Yii::setPathOfAlias ( 'views', $this->getBasePath () . DIRECTORY_SEPARATOR . 'views' );
		
		Yii::import ( 'application.components.*' );
		Yii::import ( 'application.models.*' );
		
		if (YII_DEBUG) {
			error_reporting ( E_ALL );
			$debug = new Debug();
		}else
			error_reporting ( E_ERROR );
	}

	/**
	 * 注册组件
	 *
	 * @see CWebApplication::registerCoreComponents()
	 */
	protected function registerCoreComponents() {
		parent::registerCoreComponents ();
		
		$components = array (
			'attachment' => array (
				'class' => 'Attachment' 
			),
			'mail' => array (
				'class' => 'Mail' 
			),
			'request' => array (
				'class' => 'HttpRequest' 
			),
			'clientScript' => array (
				'class' => 'ClientScript' 
			),
			'asset' => array (
				'class' => 'AssetManager' 
			),
			'session' => array (
				'class' => 'HttpSession' 
			) 
		);
		
		$this->setComponents ( $components );
	}

	/**
	 * 获取图片处理函数
	 *
	 * @return Imager the image manager
	 */
	public function getAttachment() {
		return $this->getComponent ( 'attachment' );
	}

	/**
	 * 获取邮件处理函数
	 *
	 * @return Imager the image manager
	 */
	public function getMail() {
		return $this->getComponent ( 'mail' );
	}
}